<?php

	class ArticleAction extends BaseAction{
		
		public function index(){
			$articleModel = M("Article");
			$type=$this->_param("type");
			import('ORG.Util.Page'); // 导入分页类
			if($type){
				$where['type']=$type;
				$this->assign("type",$type);
				}
			$count = $articleModel->where($where)->count(); // 查询满足要求的总记录数 $map表示查询条件
			$Page = new Page($count, 15); // 实例化分页类 传入总记录数
			$show = $Page->show(); // 分页显示输出
			// 进行分页数据查询
			$list = $articleModel->where($where)->limit($Page->firstRow . ',' . $Page->listRows)->select();
			$this->assign('list', $list); // 赋值数据集
			$this->assign('page', $show); // 赋值分页输出
			$this->assign('num', count($list));
			$this->display();
			}
		
		public function content(){
			$id=$this->_param(id);
			$articleModel = M("Article");
			$article=$articleModel->select($id);
			$this->assign("article",$article[0]);
			$prev=$this->getPrev($id);
			$next=$this->getNext($id);
			$this->assign("prev",$prev);
			$this->assign("next",$next);
			$this->display();
			}
		
		public function count(){
			$id=$this->_param(id);
			$articleModel = M("Article");
			$articleModel->where("id=$id")->setInc("click");
			}	
		
		public function getPrev($id){
			$articleModel = M("Article");
			while(!$article=$articleModel->select(--$id)){
				if($id<$articleModel->min("id")) break;
				}
			return $article[0];
			}
		
		public function getNext($id){
			$articleModel = M("Article");
			while(!$article=$articleModel->select(++$id)){
				if($id>$articleModel->max("id")) break;
				}
			return $article[0];
			}	
		
		}

?>